source code Hệ thống quản lý đồn cảnh sát bằng C++

1 /* Police Station Management System using C++ and compiled using GCC Compiler */
2
3 #include<iostream>
4 #include<conio.h>
5 #include<ctype.h>
6 #include<direct.h>
7 #include<process.h>
8 #include<windows.h>
9 #include<
string.h>
10 #include<stdio.h>
11 #include<fstream>
12 #include<
string.h>
13 #include<stdlib.h>
14 #include<iomanip>
15 #include<time.h>

16
17
18 using
namespace std;
19
20 /* Defining functions */

21
22 int
login(); // function for loginscreen
23 void
mainpage(); // function to display mainpage
24 void
date1(); // to get current date
25 void
delay(); // function for loading effect
26 void
callExit(); // exit function
27
28
29 /* Structure
for Date of arrest */
30
31 struct
date
32 {
33   
int d;
34   
int m;
35   
int y;
36 };

37
38 /* Structure
for Details of Crime of Criminal */
39
40 struct
court
41 {
42   
char crime[20];
43   
char act[20];
44   
char cour[20];
45   
char state[20];
46 };

47
48 /* Structure
for Physical Description of Criminal */
49
50 struct
descp
51 {
52   
char colour[20];
53   
char face[20];
54   
char imark[20];
55   
char height[6];
56   
char eye_color[20];
57 };

58
59 /* Structure
for Details of F.I.R. */
60
61 struct
police
62 {
63   
char station[50];
64   
char fir_no[10];
65   date date_arrest;
66 };

67
68 int
login()
69 {
70   
char username[30];
71   
char password[30];
72   
int true1 = 1;
73   
int try1 = 0;
74   
int i=0;
75   
do
76   {
77     system(
"cls");
78     cout <<
"\n\n\n\n\n\n";
79     cout <<
"\t\t\t\t ----------------------------------\n";
80     cout <<
"\t\t\t\t |POLICE STATION MANAGEMENT SYSTEM|\n";
81     cout <<
"\t\t\t\t ----------------------------------\n";
82     cout <<
"\n\n";
83     cout <<
"\t\t\t\t\t";
84     cout <<
"Username : ";
85     cin >> username;
86     cout <<
"\t\t\t\t\t";
87     cout <<
"\n";
88     cout <<
"\t\t\t\t\t";
89     cout <<
"Password : ";
90     cin >> password;
91     
if(strcmp(username,"admin")==0 && strcmp(password,"pass")==0)
92       {
93         cout <<
"\n\n";
94         cout <<
"\t\t\t\t";
95         cout <<
"You are accessed to the system!\n\n";
96         cout <<
"\t\t\t\t";
97         system(
"pause");
98         system(
"cls");
99         true1 =
0;
100         
return 1;
101       }
102       
else
103       {
104         system(
"cls");
105         try1 = try1+
1;
106         cout <<
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
107         cout <<
"\t\t\t\t\t";
108         cout <<
"No. of attempts remain: " << 3-try1;
109         cout <<
"\n\n";
110         cout <<
"\t\t\t\t";
111         system(
"pause");
112         
if(try1>=3)
113         {
114
115           cout <<
"\t\t\t\t\t\t";
116           cout <<
"\n";
117           cout <<
"\t\t\t\t";
118           cout <<
"No permission to enter the system!\n\n";
119           cout <<
"\t\t\t\t";
120           system(
"pause");
121           callExit();
122         }
123       }
//END OF ELSE
124     }
125  
while(try1<3);
126 }

127
128 void
delay(unsigned int mseconds)
129 {
130     clock_t goal = mseconds + clock();
131     
while (goal > clock());
132 }

133
134 void
mainpage()
135 {
136   
int process=0;
137   system(
"cls");
138   date1();
139   cout <<
"\n";
140   cout <<
"\t\t\t\t ----------------------------------\n";
141   cout <<
"\t\t\t\t |POLICE STATION MANAGEMENT SYSTEM|\n";
142   cout <<
"\t\t\t\t ----------------------------------\n";
143   cout <<
"\n\n";
144   cout <<
"\t\t\t\t";
145   cout <<
"Prepared By ";
146   cout <<
":";
147   cout <<
" Chetan Khunti";
148   cout <<
"\n\n";
149   cout <<
"\t\t\t\t";
150   cout <<
"Mini Project ";
151   cout <<
":";
152   cout <<
" Police Station Management System";
153   cout <<
"\n\n";
154   cout <<
"\t\t\t\t";
155   cout <<
"\n\n";
156   cout <<
"\n\n";
157   cout <<
"\t\t\t\t";
158   system(
"pause");
159   cout <<
"\n\t\t\t\tLoading";
160
161   
for(process=0;process<25;process++)
162   {
163     delay(
150);
164     cout <<
".";
165   }
166 }

167
168 void
callExit()
169 {
170   
int process = 0;
171   system(
"cls");
172   cout <<
"\n\n\n\n\n";
173   cout <<
"\n\tTaking You Out of The System";
174   
for(process=0;process<25;process++)
175     {
176       delay(
150);
177       cout <<
".";
178     }
179   system(
"cls");
180   cout <<
"\n\n\n\n\n\n\n\n\n\n\n";
181   cout <<
"\t\t\t\t\t";
182   cout <<
"You are out of the System.\n";
183   cout <<
"\t\t\t\t\t\t";
184   cout <<
"Thank You !";
185   cout <<
"\n\n";
186   cout <<
"\t\t\t\t\t";
187   system(
"pause");
188   exit(
0);
189 }

190
191 void
date1()
192 {
193   time_t T= time(NULL);
194   
struct tm tm = *localtime(&T);
195   cout <<
"\n\n\n";
196   cout <<
"\t\t\t\t\t Date:" << tm.tm_mday << "/" << tm.tm_mon+1 << "/" << tm.tm_year+1900 << "\n";
197 }

198
199 /*
"CRIMINAL" class for getting all information about convict */
200
201 class
criminal
202 {

203 private
:
204   
char name[20];
205   
char sex[3];
206   
char conno[10];
207   
char age[4];
208   
char address[50];
209   court COURT;
210   police POLICE;
211   descp des;
212   
public:
213   
int ncheck(char arr[]); // function to check that input is non-numeric
214   
int s_check(char a[]); // function to check sex has only 1 character "M" or "F"
215   
void input(void); // function to take input
216   
void output(void); // function for displaying output
217   
void delete_rec(char con_no[]); // function to delete a record
218   
int dcheck(char n[]); // function to search convict id in file
219   
void display(); // function to display all records
220   
void remove(); // function to remove an entry
221   
void modify(); // function to modify existing records
222   
void list(); // function to list all records
223   
void empty(); // function to enter new record while modifying
224   
int concheck(char b[]); // function to check convict ID
225
226 };

227
228 // end of
class criminal
229
230 void
menu(criminal l)
231 {
232   
int input;
233   
while(true)
234   {
235     system(
"cls");
236     cout <<
"\n\n\n";
237     cout <<
"\t\t\t\t\t";
238     cout <<
"\n";
239     cout <<
"\t\t\t\t ----------------------------------\n";
240     cout <<
"\t\t\t\t |POLICE STATION MANAGEMENT SYSTEM|\n";
241     cout <<
"\t\t\t\t ----------------------------------\n";
242     cout <<
"\n\n\n\n";
243     cout <<
"\t\t\t\t";
244     cout <<
" 1. ADD RECORD\n\n";
245     cout <<
"\t\t\t\t";
246     cout <<
" 2. MODIFY RECORD\n\n" ;
247     cout <<
"\t\t\t\t" ;
248     cout <<
" 3. DISPLAY RECORD\n\n" ;
249     cout <<
"\t\t\t\t" ;
250     cout <<
" 4. DELETE RECORD\n\n" ;
251     cout <<
"\t\t\t\t" ;
252     cout <<
" 5. LIST ALL RECORDS\n\n" ;
253     cout <<
"\t\t\t\t" ;
254     cout <<
" 6. EXIT\n\n" ;
255     cout <<
"\t\t\t\t" ;
256     cout <<
"Choose Option:[1/2/3/4/5/6] : " ;
257     fflush(stdin);
258     cin >> input;
259     
switch(input)
260     {
261       
case 1:
262       {
263         l.input();
264         
break;
265       }
266       
case 2 :
267       {
268         l.modify();
269         
break;
270       }
271       
case 3:
272       {
273         l.display();
274         
break;
275       }
276       
case 4:
277       {
278         l.
remove() ;
279         
break;
280       }
281       
case 5:
282       {
283         l.list();
284         
break;
285       }
286       
case 6:
287       {
288         callExit();
289       }
290       
break;
291
292       
default:
293       {
294         cout <<
"\n\n\n" ;
295         cout <<
"\t\t\t\t" ;
296         cout <<
" Invalid input!" ;
297         cout <<
"\n\n" ;
298         cout <<
"\t\t\t\t" ;
299         fflush(stdin);
300         getchar();
301         menu(l);
302       }
303     }
304   }
305 }

306
307 /* function to check that input
is non-numeric */
308
309 int
criminal::ncheck (char arr[])
310 {
311   
int i=0;
312   
while (arr[i]!='\0')
313   {
314     
if (((arr[i] > 64) && (arr[i] < 92)) || ((arr[i] > 95) && (arr[i] < 124)) || (arr[i] ==' '))
315     {
316
317       i++;
318       
continue;
319     }
320     
else
321     {
322       cout <<
"\n\tIncorrect input. Try again !\n ";
323       
return 0;
324     }
325   }
326   
return 1;
327 }

328
329 /* function to check sex has only
1 character "M" or "F" */
330
331 int
criminal::s_check(char a[])
332 {
333   
if(( (a[0]=='m')||(a[0]=='f')||(a[0]=='M')||(a[0]=='F'))&&(a[1]=='\0') )
334   {
335     
return 1;
336   }
337   
else
338   {
339     cout <<
"\n\tIncorrect input. Try again !\n";
340     
return 0;
341   }
342 }

343
344 void
criminal::input() // Function for getting Convicts Record
345
346
347 {
348   system(
"cls");
349   
this->empty();
350   criminal x;
351   
int c = 0 ;
352   fflush(stdin);
353   fstream filin;
354   filin.open(
"jail.txt",ios::app);
355
356   
while(c != 1)
357   {
358     cout <<
"\n\n\n\tENTER THE CONVICT ID : ";
359     cin >> (
this->conno);
360     c = x.concheck(
this->conno);
361     fflush(stdin);
362   }
363   c =
0;
364   cout <<
"\n\n ENTER THE CONVICT DETAILS\n";
365   
while(c != 1)
366   {
367     cout <<
"\n" << setw(10) <<"\tNAME : ";
368     cin >> (
this->name);
369     c = ncheck(
this->name);
370   }
371   fflush(stdin);
372   c =
0;
373   
while(c != 1)
374   {
375     cout <<
"\n" << setw(10) << "\tSEX : ";
376     cin >> (
this->sex);
377     c = s_check(
this->sex);
378   }
379   fflush(stdin);
380   cout <<
"\n" << setw(10) << "\tADDRESS : ";
381   cin >> (
this->address);
382   fflush(stdin);
383   cout <<
"\n" << setw(10) << "\tAGE : ";
384   cin >> (
this->age);
385
386   cout <<
"\n\n ENTER THE COURT DETAILS\n";
387   fflush(stdin);
388   c =
0 ;
389   
while(c != 1)
390   {
391     cout <<
"\n\n\tCOURT OF CONVICTION : ";
392     cin >> (
this->COURT.cour);
393     c = ncheck(
this->COURT.cour);
394   }
395   fflush(stdin);
396   c =
0;
397   
while(c != 1)
398   {
399     cout <<
"\n\tSTATE : ";
400     cin >> (
this->COURT.state);
401     c = ncheck(
this->COURT.state);
402   }
403   fflush(stdin);
404   c =
0;
405   
while(c != 1)
406   {
407     cout <<
"\n\tCRIME : ";
408     cin >> (
this->COURT.crime);
409     c = ncheck(
this->COURT.crime);
410   }
411   fflush(stdin);
412   cout <<
"\n\tACT : ";
413   cin >> (
this->COURT.act);
414
415   system(
"cls");
416
417   cout <<
"\n ENTER DESCRIPTION\n\n\t ";
418   fflush(stdin);
419   c =
0;
420   
while(c != 1)
421   {
422     cout<<
"\n\tSKIN COMPLEXTION : ";
423     cin >> (
this->des.colour);
424     c = ncheck(
this->des.colour);
425   }
426   fflush(stdin);
427   c =
0;
428   
while(c != 1)
429   {
430   cout <<
"\n\tFACE DESCRIPTION : ";
431   cin >> (
this->des.face);
432   c = ncheck(
this->des.face);
433   }
434   fflush(stdin);
435   cout <<
"\n\tHEIGHT : ";
436   cin >> (
this->des.height);
437
438   fflush(stdin);
439   cout <<
"\n\tIDENTIFICATION MARKS : ";
440   cin >> (
this->des.imark);
441   fflush(stdin);
442   cout <<
"\n\tEYE COLOUR : ";
443   cin >> (
this->des.eye_color);
444
445   system(
"cls");
446
447   cout <<
"\n\n ENTER POLICE STATION INFORMATION \n\n\t\t ";
448   cout <<
"\n\n\n\t\t";
449   fflush(stdin);
450   cout <<
"\n\t\tPOLICE STATION : ";
451   cin >> (
this->POLICE.station);
452   cout <<
"\n\t\tFIR NO. : ";
453   fflush(stdin);
454   cin >> (
this->POLICE.fir_no);
455   cout <<
"\n\t\tDATE OF ARREST(DD/MM/YYYY)\n";
456   fflush(stdin);
457   c =
0;
458   
while(!c)
459   {
460     cout <<
"\n\t\t\t\t\t Day : ";
461     cin >>
this->POLICE.date_arrest.d;
462     
if((this->POLICE.date_arrest.d>31) || (this->POLICE.date_arrest.d<1))
463     {
464       cout <<
"\n\t\tTHIS DATE DOES NOT EXIST, TRY AGAIN!!\n";
465       c =
0;
466     }
467     
else
468       c =
1;
469   }
470   c =
0;
471   fflush(stdin);
472   
while(!c)
473   {
474     cout <<
"\n\t\t\t\t\t Month : ";
475     cin >>
this->POLICE.date_arrest.m;
476     
if((this->POLICE.date_arrest.m>12) || (this->POLICE.date_arrest.m<1))
477     {
478       cout <<
"\n\t\tTHIS MONTH DOES NOT EXIST, TRY AGAIN!!\n";
479       c =
0;
480       
continue;
481     }
482     
else
483       c =
1;
484
485     
if((this->POLICE.date_arrest.d==31) && ((this->POLICE.date_arrest.m==2) || (this->POLICE.date_arrest.m==4) ||( this->POLICE.date_arrest.m==6) ||( this->POLICE.date_arrest.m==9) || (this->POLICE.date_arrest.m==11)))
486     {
487       cout <<
"\n\t\tTHIS MONTH DOES NOT HAVE 31 DAYS \n\tTRY AGAIN !!\n";
488       c =
0;
489     }
490     
else
491       c =
1;
492   }
493   fflush(stdin);
494   c =
0;
495
496   
while(!c)
497   {
498     cout <<
"\n\t\t\t\t\t Year(4 digits) : ";
499     cin >>
this->POLICE.date_arrest.y;
500     
if((this->POLICE.date_arrest.y <= 1930)||(this->POLICE.date_arrest.y>2017))
501     {
502       cout <<
"\n\t\tINCORRECT INPUT, TRY AGAIN!!\n";
503       c =
0;
504     }
505     
else
506       c =
1;
507   }
508   
char ch;
509   
do
510   {
511     cout <<
"\n\tDO YOU WANT TO SAVE THIS INFORMATION(Y/N) : ";
512     cin >> ch;
513
514     
if(ch=='y'||ch=='Y')
515     {
516       cout <<
"\n\n\t< RECORD HAS BEEN SAVED >";
517       filin.write((
char*)this,sizeof(criminal));
518     }
519    
else
520     {
521       
if((ch!='n')&&(ch!='N'))
522       {
523         cout<<
"\n\t\tENTER CORRECTLY \n\t\t TRY AGAIN !!\n\n";
524       }
525     }
526   }
527   
while((ch!='y') && (ch!='Y') && (ch!='n') && (ch!='N'));
528
529   filin.close();
530   cout <<
"\n\n\t\t";
531   system(
"pause");
532
533 }

534
535 void
criminal::output() // Function for showing Convict's Record
536 {
537   system(
"cls");
538   fflush(stdin);
539
540   cout <<
"\n\n\t\t----------PERSONAL RECORD OF CONVICT----------";
541   cout <<
"\n\n\tCONVICT ID :\t";
542   puts(conno);
543   cout <<
"\n\tNAME :\t";
544   puts(
this->name);
545   cout <<
"\n\tSEX :\t" << this->sex;
546   cout <<
"\n\n\tADDRESS :\t";
547   puts(
this->address);
548   cout <<
"\n\tAGE :\t";
549   puts(
this->age);
550   cout <<
"\n\n\n\t\t\t";
551   system(
"pause");
552
553
554   system(
"cls");
555   cout <<
"\n\n\t\t----------CRIMINAL RECORD----------";
556   cout <<
"\n\n\t\t\tCOURT INFORMATION\n\n ";
557   cout <<
"\n\t1. COURT OF CONVICTION :\t";
558   puts(
this->COURT.cour);
559   cout <<
"\n\t2. STATE :\t";
560   puts(
this->COURT.state);
561   cout <<
"\n\t3. CRIME :\t";
562   puts(
this->COURT.crime);
563   cout <<
"\n\t4. ACT :\t";
564   puts(
this->COURT.act);
565   cout <<
"\n\n\n\t\t\t";
566   system(
"pause");
567   system(
"cls");
568
569   cout <<
"\n\n\t\t\tDESCRIPTION\n";
570
571   cout <<
"\n\t1. SKIN COMPLEXTION :\t";
572   puts(
this->des.colour);
573   cout <<
"\n\t2. FACE :\t";
574   puts(
this->des.face);
575   cout <<
"\n\t3. IDENTIFICATION MARK :\t";
576   puts(
this->des.imark);
577   cout <<
"\n\t4. HEIGHT :\t";
578   puts(
this->des.height);
579   cout <<
"\n\t5. EYE COLOUR :\t";
580   puts(
this->des.eye_color);
581   cout <<
"\n\n\n\t\t\t";
582   system(
"pause");
583
584   system(
"cls");
585
586   cout <<
"\n\n\n\t\tPOLICE INFORMATION \n\n";
587   cout <<
"\n\t1. POLICE STATION :\t";
588   puts(
this->POLICE.station);
589   cout <<
"\n\t2. FIR NO. :\t";
590   puts(
this->POLICE.fir_no);
591   cout <<
"\n\t3. DATE OF ARREST :\t" << this->POLICE.date_arrest.d <<"/" << POLICE.date_arrest.m << "/"<<this->POLICE.date_arrest.y;
592   cout <<
"\n\n\n\t\t\t";
593   system(
"pause");
594 }
//end of output function
595
596
597 void
criminal::delete_rec(char con_no[]) // function for deleting a record
598 {
599   fstream filin;
600   fflush(stdin);
601   filin.open(
"jail.txt",ios::in|ios::ate);
602   
int q = filin.tellg();
603   
int c = q/sizeof(criminal);
604   fstream temp;
605   temp.open(
"temp.txt",ios::out);
606   filin.seekg(
0,ios::beg);
607   
for(int i=0; i<c; i++)
608   {
609     filin.read((
char*)this,sizeof(criminal));
610     
if(strcmp(con_no,conno) != 0)
611     temp.write((
char*)this,sizeof(criminal));
612   }
613   filin.close();
614   temp.close();
615   filin.open(
"jail.txt",ios::out);
616   temp.open(
"temp.txt",ios::in|ios::ate);
617   
int a = temp.tellg();
618   
int size = a/sizeof(criminal);
619   temp.seekg(
0,ios::beg);
620   
for(int k=0; k<size; k++)
621   {
622     temp.read((
char*)this,sizeof(criminal));
623     filin.write((
char*)this,sizeof(criminal));
624   }
625   filin.close();
626   temp.close();
627   cout<<
"\n\n\t\t< THE RECORD HAS BEEN DELETED >";
628   cout <<
"\n";
629   fflush(stdin);
630   getchar();
631 }

632
633 int
criminal::dcheck(char n[]) // function to check correct format of date
634 {
635   system(
"cls");
636   fstream file;
637   file.open(
"jail.txt",ios::in|ios::ate|ios::binary);
638
639   
int x = 0, count = 0, c;
640   
int q = file.tellg();
641   c = q/
sizeof(criminal);
642   file.close();
643   file.open(
"jail.txt",ios::in|ios::binary);
644   
for(int i=0;i<c;i++)
645   {
646     file.read((
char*)this,sizeof(criminal));
647     count++;
648     
if(strcmp(n,conno)==0)
649     {
650       x++;
651       
break;
652     }
653   }
654   
if(x==0)
655   {
656     cout<<
"\n\n\n\n\tCONVICT NOT FOUND!! ";
657     getchar();
658     
return 0;
659   }
660   
else
661   {
662     
return count;
663   }
664   file.close();
665 }

666
667 void
criminal::display() // function to display record
668 {
669   system(
"cls");
670   fflush(stdin);
671   
char N[10];
672   
int rec;
673   
int loc;
674   cout <<
"\n\n\n\t\tENTER THE CONVICT ID : ";
675   gets(N);
676   fstream file;
677   rec =
this->dcheck(N);
678   file.open(
"jail.txt",ios::in|ios::binary);
679   
if(rec!=0)
680   {
681     loc = (rec-
1)*sizeof(criminal);
682     file.seekg(loc);
683     file.read((
char*)this,sizeof(criminal));
684     
this->output();
685   }
686 file.close();
687 cout <<
"\n";
688 fflush(stdin);
689 }

690
691 void
criminal::remove()
692 {
693   fflush(stdin);
694   system(
"cls");
695   
char no[10];
696   
int s;
697   cout <<
"\n\n\n\t\tENTER THE CONVICT ID : ";
698   gets(no);
699   s =
this->dcheck(no);
700   
if(s!=0)
701   
this->delete_rec(no);
702 }

703
704
705 void
criminal::modify() // function to modify record
706 {
707   system(
"cls");
708   fflush(stdin);
709   fstream file;
710   
char npdr[10], ncrime[10], nact[10], nstate[10], ncourt[10], nstat[10], nfir[10];
711   
char str[10],nprd[15],cno[10];
712   
int check,loc;
713   criminal x;
714   date D;
715   fflush(stdin);
716   modify_start:
717   cout <<
"\n\tENTER CONVICT ID : ";
718   gets(str);
719   check =
this->dcheck(str);
720   
if(check != 0)
721   {
722     file.open(
"jail.txt",ios::out|ios::ate);
723     
int d = 0;
724     cout <<
"\n\n\t\tRECORD FOUND !\n\n";
725     cout <<
"\n\tENTER MODIFIED DETAILS\n";
726     
while(d != 1)
727     {
728       cout <<
"\n\t\t\t\tCONVICT ID : ";
729       cin >> cno;
730       d = x.concheck(cno);
731     }
732     strcpy(conno,cno);
733
734     cout <<
"\n\t\t\t\tCRIME : ";
735     cin >> ncrime;
736     strcpy(COURT.crime,ncrime);
737     cout <<
"\n\t\t\t\tACT : ";
738     cin >> nact;
739     strcpy(COURT.act,nact);
740     cout <<
"\n\t\t\t\tSTATE : ";
741     cin >> nstate;
742     strcpy(COURT.state,nstate);
743     cout <<
"\n\t\t\t\tCOURT : ";
744     cin >> ncourt;
745     strcpy(COURT.cour,ncourt);
746     system(
"cls");
747     cout <<
"\n\t\tENTER THE MODIFIED POLICE RECORD\n";
748     cout <<
"\n\t\t\t\tSTATION : ";
749     cin >> nstat;
750     strcpy(POLICE.station,nstat);
751     cout <<
"\n\t\t\t\tFIR NO : ";
752     cin >> nfir;
753     strcpy(POLICE.fir_no,nfir);
754     cout <<
"\n\t\t\t\tDATE OF ARREST(DD,MM,YYYY) ";
755     
int c = 0;
756     
while(c != 1)
757     {
758       cout<<
"\n\t\t\t\t\t Day : ";
759       cin>>D.d;
760       
if((D.d>31)||(D.d<1))
761       {
762         cout <<
"\n\t\tTHIS DATE DOES NOT EXIST, TRY AGAIN!!\n";
763         c =
0;
764       }
765       
else
766         c =
1;
767     }
768
769     c =
0;
770     
while(c != 1)
771     {
772       cout<<
"\n\t\t\t\t\t Month : ";
773       cin >> D.m;
774       
if((D.m>12)||(D.m<1))
775       {
776         cout <<
"\n\t\tTHIS MONTH DOES NOT EXIST, TRY AGAIN!!\n";
777         c =
0;
778         
continue;
779       }
780       
else
781         c=
1;
782
783       
if((D.d==31) &&((D.m==2) || (D.m==4) ||( D.m==6) ||( D.m==9) || (D.m==11)))
784       {
785         cout <<
"\n\t\tTHIS MONTH DOES NOT HAVE 31 DAYS \n\tTRY AGAIN !!\n";
786         c =
0;
787       }
788       
else
789         c =
1;
790     }
791     c =
0;
792
793     
while(c != 1)
794     {
795       cout<<
"\n\t\t\t\t\t Year(in 4 digits) : ";
796       cin >> D.y;
797       
if((D.y <= 1930)||(D.y>2017) )
798       {
799         cout <<
"\n\t\tINCORRECT INPUT, TRY AGAIN!!\n";
800         c =
0;
801       }
802       
else
803         c =
1;
804     }
805
806     POLICE.date_arrest.d=D.d;
807     POLICE.date_arrest.m=D.m;
808     POLICE.date_arrest.y=D.y;
809
810     loc = (check-
1)*sizeof(criminal);
811     file.seekp(loc);
812     file.write((
char*)this,sizeof(criminal));
813     file.close();
814     cout <<
"\n";
815     fflush(stdin);
816     cout <<
"\n\n\t\t\t < RECORD MODIFIED >";
817   }
818
819   
else
820   {
821       cout <<
"\n\n\n\t\tPRESS 'Y' TO TRY AGAIN 'N' TO GO TO QUIT : ";
822       
char ch_m;
823       cin >> ch_m;
824       fflush(stdin);
825       
if(ch_m == 'y' || ch_m == 'Y')
826       {
827         system(
"cls");
828         
goto modify_start;
829       }
830
831       
else
832       {
833         callExit();
834       }
835   }
836 }

837
838 void
criminal::list() // function to list all criminal records
839 {
840   system(
"cls");
841   fflush(stdin);
842   
int j ;
843   fstream file;
844   file.open(
"jail.txt",ios::in|ios::ate|ios::binary);
845   
int q = file.tellg();
846   
int c = q/sizeof(criminal);
847   file.seekg(
0);
848   cout<<
" \n";
849   cout<<
" \n";
850   cout<<
" CONVICT LIST \n";
851   cout<<
" \n";
852   cout<<
" \n";
853   cout<<
"\n================================================================================\n";
854   cout<<
"SR.\tNAME\t\t\tCONVICT NO.\t\t\tCRIME\n";
855   cout<<
"================================================================================\n";
856   
int i = 0;
857   
while(file.read((char*)this,sizeof(criminal)))
858   {
859     i++;
860     cout << i <<
" ";
861     
for(j=0; j<strlen(this->name); j++)
862       cout <<
this->name[j];
863     cout<<
"\t\t\t ";
864     
for(j=0; j<strlen(this->conno); j++)
865       cout <<
this->conno[j];
866     cout <<
"\t\t\t ";
867     
for(j=0; j<strlen(this->COURT.crime); j++)
868       cout <<
this->COURT.crime[j];
869       cout <<
"\n";
870       fflush(stdin);
871       getchar();
872     cout <<
"\n--------------------------------------------------------------------------------\n";
873     
if((i%3)==0&&(i!=c))
874     {
875       system(
"pause");
876       system(
"cls");
877       cout <<
"\n================================================================================\n";
878       cout <<
"SR.\tNAME\t\t\tCONVICT NO.\t\t\tCRIME\n";
879       cout <<
"================================================================================\n";
880     }
881   }
882   file.close();
883   getchar();
884 }

885
886 void
criminal::empty()
887 {
888   
int i;
889   
for(i=0; i<20; i++)
890     name[i]=
' ';
891   
for(i=0; i<10; i++)
892     conno[i]=
' ';
893   
for(i=0; i<3; i++)
894     sex[i]=
' ';
895   
for(i=0; i<4; i++)
896     age[i]=
' ';
897   
for(i=0; i<50; i++)
898     address[i]=
' ';
899   
for(i=0; i<20; i++)
900     COURT.cour[i]=
' ';
901   
for(i=0; i<20; i++)
902     COURT.crime[i]=
' ';
903   
for(i=0; i<20; i++)
904     COURT.act[i]=
' ';
905   
for(i=0; i<20; i++)
906     COURT.state[i]=
' ';
907   
for(i=0; i<20; i++)
908     des.colour[i]=
' ';
909   
for(i=0; i<20; i++)
910     des.imark[i]=
' ';
911   
for(i=0; i<20; i++)
912     des.face[i]=
' ';
913   
for(i=0; i<6; i++)
914     des.height[i]=
' ';
915   
for(i=0; i<15; i++)
916     des.eye_color[i]=
' ';
917   
for(i=0; i<50; i++)
918     POLICE.station[i]=
' ';
919   
for(i=0; i<10; i++)
920     POLICE.fir_no[i]=
' ';
921   POLICE.date_arrest.m =
0;
922   POLICE.date_arrest.d =
0;
923   POLICE.date_arrest.y =
0;
924 }

925
926 int
criminal::concheck(char b[])
927 {
928   fstream file;
char a[10];
929   
int check=0;
930   file.open(
"jail.dat",ios::in|ios::ate);
931   
int q=file.tellg();
932   
int size=q/sizeof(criminal);
933   file.seekg(
0,ios::beg);
934   
for(int i=0;i<size;i++)
935   {
936     file.read((
char*)this,sizeof(criminal));
937     strcpy(a,conno);
938     
if(strcmp(b,a)==0)
939     {
940       check+=
1;
941       
break;
942     }
943   }
944   
if(check==0)
945   {
946     
return 1;
947   }
948   
else
949   {
950     cout<<
"\tGIVEN CONVICT CODE ALREADY EXISTS!"<<endl;
951     
return 1;
952   }
953   file.close();
954 }

955
956 int
main()
957 {
958   system(
"cls");
959   mainpage();
960   criminal l;
961   
int x,res=1;
962   res = login();
963
964   
if(res == 1)
965   {
966     menu(l);
967   }
968 }


Gõ tìm kiếm nhanh...